﻿<?php
@session_start();
require_once("../../class/mysql.class.php");
if (!isset($_GET['id_sortie'])) {
	header('location:../../list_sortie.php?action=error');  
}else{
$obj = new Mysql ();
      
      $requte="DELETE FROM `st_attr_sortie` WHERE `id_sortie`='".$_GET["id_sortie"]."'";
      $resultat=mysql_query($requte);

      //get qt from article 
      $s = "SELECT Quantite from st_article WHERE id_article = ".$_GET['id_article'];
      echo '<br> SELECT QT => '.$s.'<br>';
      $r = mysql_query($s);
      $QT_article = mysql_fetch_array($r);
      echo '<br> la qt recuperer = '.$QT_article['Quantite'].'<br>';
      echo '<br> la qt q ajouter au stock = '.$_GET['qt'].'<br>';
      $newQt = (int)$QT_article['Quantite'] + (int)$_GET['qt'];
      //update to new qt
      $up = "UPDATE st_article SET Quantite = ".$newQt." WHERE id_article = ".$_GET['id_article'];
      echo '<br> UPDATE => '.$up.'<br>';
      mysql_query($up);

      //get all entry by id and test if num_rows is null to delete the global entry
      //get qt from article 
      /*$ss = "SELECT * from st_attr_sortie WHERE id_sortie = ".$_GET['id_sortie'];
      //echo '<br> SELECT QT => '.$ss.'<br>';
      $rr = mysql_query($ss);
      $nb = mysql_num_rows($rr);
      if($nb == 0){
      	//aucune entree -> delete entry
      	$requte_del="DELETE FROM `st_sortie` WHERE `id_article`='".$_GET["id_article"]."'";
      	mysql_query($requte_del);
      }*/

      //redirect
      header('location:../../list_sortie.php?action=sortie&page=list_sortie');  
}
	  
?>